package cn.uniquetech.amlss;

import cn.uniquetech.util.FileUtil;

public class GenControllerUtil {
	public static String parseControllerClass(String tableName, String tableRemarks) {
		String servicePackage = GenerateCode.PACKAGENAME + ".controller";
		String clazz = tableName;
		StringBuffer sb = new StringBuffer();
		sb.append("package " + servicePackage + ";\r\n\r\n");
		sb.append("import org.springframework.beans.factory.annotation.Autowired;\r\n");
		sb.append("import org.springframework.stereotype.Controller;\r\n");
		sb.append("import org.springframework.web.bind.annotation.RequestMapping;\r\n");
		sb.append("import cn.uniquetech.controller.base.BaseController;\r\n");
		sb.append("import cn.uniquetech.entity." + clazz + "VO" + ";\r\n");
		sb.append("import cn.uniquetech.service.I" + clazz + "Service;\r\n");
		sb.append("\r\n");
		sb.append("\r\n/**" + tableRemarks + "**/");
		sb.append("\r\n");
		sb.append("@Controller");
		sb.append("\r\n");
		sb.append("@SuppressWarnings(\"unused\")");
		sb.append("\r\n");
		sb.append("@RequestMapping(value = \"/" + clazz.toLowerCase() + "\")");
		sb.append("\r\n");
		sb.append("public class " + clazz + "Controller extends BaseController<" + clazz + "VO" + ">" + "{\r\n\r\n");
		sb.append("private I" + clazz + "Service " + clazz.toLowerCase() + "Service;" + "\r\n");
		sb.append("@Autowired\r\n");
		sb.append("public " + clazz + "Controller(I" + clazz + "Service " + clazz.toLowerCase() + "Service) {\r\n");
		sb.append("\t\tsuper();\r\n");
		sb.append("\t\t" + "this." + clazz.toLowerCase() + "Service = " + clazz.toLowerCase() + "Service;" + "\r\n");
		sb.append("\t\t" + "this.baseService = " + clazz.toLowerCase() + "Service;" + "\r\n");
		sb.append("\t\t" + "this.ctrlModel = \"" + clazz.toLowerCase() + "\";" + "\r\n");
		sb.append("\t\t" + "this.ctrlName = \"" + clazz.toLowerCase() + "\";\r\n");
		sb.append("\t}\r\n");
		sb.append("}\r\n");
		FileUtil.writeFile(servicePackage, clazz + "Controller.java", sb.toString());
		return sb.toString();
	}
}
